package com.chenjt.activiti.exception;

import com.chenjt.activiti.ResultModel;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * 注释：全局异常拦截
 *
 * @author chenjt
 * @date 2022/5/18 14:54
 */
@RestControllerAdvice
public class GlobalExceptionHandler {

    private static final Logger log = LoggerFactory.getLogger(GlobalExceptionHandler.class);



    /**
     * 拦截未知的运行时异常
     */
    @ExceptionHandler(RuntimeException.class)
    public ResultModel notFount(RuntimeException e)
    {
        log.error("运行时异常:", e);
        return ResultModel.error(500,"运行时异常");
    }

    /**
     * 系统异常
     */
    @ExceptionHandler(Exception.class)
    public ResultModel handleException(Exception e)
    {
        log.error(e.getMessage(), e);
        return ResultModel.error(500,"服务器错误");
    }




}
